﻿@{
    ViewBag.Title = "DQ配置新增";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@model  Model.DQRulesConfig
@section Head{
    <style>
        .searchArea
        {
            line-height: 25px;
        }
        .sel
        {
            width: 130px;
        }
    </style>
}
<script type="text/javascript">
    var columnArr = new Array();
    $(function () {
        $("#link a").each(function () {
            $(this).attr("href", $(this).attr("href") + "?modelID=" + $.getUrlParam("modelID") + "&dbName=" + encodeURI($.getUrlParam("dbName")));
        });
        var parent = window.dialogArguments;
        var model = { ColumnName: "", Operator: "" };
        if ($.getUrlParam("id") && $.getUrlParam("id") != "") {
            model = parent.retData[$.getUrlParam("id")];
            $("#hid_GUID").val($.getUrlParam("id"));
            $("#txt_ColumnDesc").val(model.ColumnDesc);
            $("#sel_LegalType").val(model.LegalType);
            $("#txt_Rules").val(model.Rules);
            if (model.UniqueConstraint == 1)
                $("#chk_UniqueConstraint").attr("checked", "checked");
        }
        $.post("/ODSConfig/GetStging_dbInfo/?modelID=" + $.getUrlParam("modelID") + "&dbName=" + encodeURI($.getUrlParam("dbName")), function (result) {
            var sysArr = new Array();
            for (var i = 0; i < result.rows.length; i++) {
                var sysIDsed = "";
                var tbIDsed = "";
                var sID = result.rows[i].SourceSystemID.replaceall("-", "");

                if (model.ColumnName.indexOf(sID) > -1)
                    sysIDsed = " selected";
                if (model.ColumnName.indexOf(result.rows[i].ViewName) > -1) {
                    tbIDsed = " selected";
                    GetColList(result.rows[i].ViewName, model.ColumnName);
                }

                if (sysArr.indexOf(result.rows[i].SourceSysName) == -1)
                    $(".sysID").append("<option value='" + sID + "' " + sysIDsed + ">" + result.rows[i].SourceSysName + "</option>");
                if (result.rows[0].SourceSysName == result.rows[i].SourceSysName)
                    $(".tbID").append("<option value='" + result.rows[i].ViewName + "' " + tbIDsed + ">" + result.rows[i].DisplayName + "</option>");
                var col = { "SourceSysNameID": sID, "DisplayName": result.rows[i].DisplayName, "ViewName": result.rows[i].ViewName };
                columnArr.push(col);
                sysArr.push(result.rows[i].SourceSysName);
            }

        });
        $.post("/DQConfig/GetOperatorList", function (result) {
            for (var i = 0; i < result.length; i++) {
                var sed = "";
                if (model.Operator == result[i].LegalOperator)
                    sed = " selected";
                $("#sel_Operator").append("<option value='" + result[i].LegalOperator + "' " + sed + ">" + result[i].LegalOperator + "</option>");
            }
        });
    });
    function GetTBList(v, s) {
        $(".tbID").empty();
        $(".colID").empty();
        $(".tbID").append("<option value=''>-请选择-</option>");
        for (var i = 0; i < columnArr.length; i++) {
            if (columnArr[i].SourceSysNameID == v) {
                $(".tbID").append("<option value='" + columnArr[i].ViewName + "'>" + columnArr[i].DisplayName + "</option>");
            }
        }
    }
    function GetColList(v, s) {
        $(".colID").empty();
        $.post('/ODSConfig/GetTableInfo?tableName=' + v + '&dbName=' + encodeURI($.getUrlParam("dbName")), function (result) {
            if (result.rows) {
                for (var i = 0; i < result.rows.length; i++) {
                    var a = $(".sysID").find("option:selected").text() + "_" +
                $(".tbID").find("option:selected").text() + "_" + result.rows[i].ColumnName;
                    var sed = "";
                    if (s.indexOf(dqColumnStr + result.rows[i].ColumnName) > -1)
                        sed = " selected";
                    $(".colID").append("<option value='" + a + "' " + sed + ">" + result.rows[i].ColumnName + "</option>");
                }
            }
        });
    }
    function save() {
        if ($.trim($(".colID").val()) == "") {
            alert("请选择完整字段名称。");
            return false;
        }
        var retArr = new Array();
        retArr = jv.GetDivArray(".searchArea", 4);
        retArr["ColumnName"] = $(".tbID").val() + dqColumnStr + $(".colID").find("option:selected").text();
        if ($.getUrlParam("id") && $.getUrlParam("id") != "") {
            retArr["Edit"] = true;
        }
        returnParent(retArr);
        return false;
    }
</script>
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/edit.png" />
            </td>
            <td width="300">
                数据质量-新增字段配置
            </td>
            <td align="right">
                <input type="button" class="button" value="完成" onclick="save();" />
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td align="right">
                字段名称：
            </td>
            <td>
                <input type="hidden" id="hid_GUID" />
                <select class="sysID sel" onchange="GetTBList(this.value,'')">
                </select>_
                <select class="tbID sel" onchange="GetColList(this.value,'')">
                    <option value="">-请选择-</option>
                </select>_
                <select id="sel_DisplayName" class="colID sel">
                    <option value="">-请选择-</option>
                </select>
            </td>
        </tr>
        <tr>
            <td align="right">
                条件描述：
            </td>
            <td>
                <input type="text" id="txt_ColumnDesc" style="width: 400px;" /><br />
            </td>
        </tr>
        <tr>
            <td align="right">
                操作符：
            </td>
            <td>
                <input type="hidden" id="sel_LegalType" value="非法规则" />
                <select id="sel_Operator" class="sel">
                    <option value="">-请选择-</option>
                </select>
            </td>
        </tr>
        <tr>
            <td align="right" valign="top">
                规则：
            </td>
            <td>
                <input type="text" id="txt_Rules" style="width: 400px;" /><br />
                （例：设置条件字段Name=abc，符合条件的数据将被过滤到数据质量数据集）
            </td>
        </tr>
        <tr>
            <td align="right">
                唯一约束：
            </td>
            <td>
                <input type="checkbox" id="chk_UniqueConstraint" value="1" />
            </td>
        </tr>
    </table>
</div>
